package com.yanqu.road.server.cmd.activity.xiuxian.cross;

import com.yanqu.road.entity.activity.xiuxian.data.XiuXianUserData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XiuXianProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.xiuxian.XiuXianModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CROSS_XIU_XIAN_GET_PVP_END_DATA, desc = "跨服同步pvp结束数据")
public class XiuXianGetPvpEndDataFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (player != null) {
            XiuXianModule xiuXianModule = player.getModule(XiuXianModule.class);
            XiuXianUserData userData = xiuXianModule.getUserData();
            if (userData == null) {
                return;
            }
            XiuXianProto.CrossXiuXianPvpEndDataRespMsg crossDataMsg = XiuXianProto.CrossXiuXianPvpEndDataRespMsg.parseFrom(packet.getBytes());
            XiuXianProto.XiuXianPvpEndDataRespMsg.Builder respMsg = XiuXianProto.XiuXianPvpEndDataRespMsg.newBuilder();
            respMsg.setRet(0);
            respMsg.addAllEndData(crossDataMsg.getEndDataList());
            userData.setPvpEndRound(crossDataMsg.getEndRound());
            player.sendPacket(ClientProtocol.U_XIU_XIAN_GET_PVP_END_DATA, respMsg);
            // 完事同步下活动数据
            xiuXianModule.syncPvpActivityData();
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
